home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DDJ0192.ARJ / TIMING.C < prev    next >
C/C++ Source or Header  |  1991-09-04  |  3KB  |  100 lines

  1. /******************************************************************
  2.  *                                                                *
  3.  * TIMING.C    -  simple non-rigorous benchmark for               *
  4.  *                Phar Lap's 286 | DOS Extender                   *
  5.  *                Intel 386 CodeBuilder                           *
  6.  *                                                                *
  7.  * Compile with:                                                  *
  8.  * ICC timing.c graphics.lib                                      *
  9.  * (386 protected mode)                                           *
  10.  * OR:                                                            *
  11.  * CL -AL -Lp -G2 -Ox timing.c graphp.obj llibpe.lib graphics.lib *
  12.  * (286 protected mode)                                           *
  13.  * OR:                                                            *
  14.  * CL -AL -G2 -Ox timing.c graphics.lib                           *
  15.  * (real mode)                                                    *
  16.  *                                                                *
  17.  ******************************************************************/
  18. #include <stdio.h>
  19. #include <graph.h>
  20. #include <time.h>
  21.  
  22. #define time_mark time_it(0)
  23. #define time_done time_it(1)
  24.  
  25. main()
  26.   {
  27.   printf("Timing graphics operations\n");
  28.   time_mark;
  29.   gtest();
  30.   time_done;
  31.   printf("Timing file operations\n");
  32.   time_mark;
  33.   ftest();
  34.   time_done;
  35.   exit(0);
  36.   }
  37.  
  38. /* Function to mark times */
  39. int time_it(int flag)
  40.   {
  41.   static clock_t sttime;
  42.   unsigned s;
  43.   if (!flag)
  44.     {
  45.     sttime=clock();
  46.     }
  47.   else
  48.     {
  49.     s=(clock()-sttime)/CLK_TCK;
  50.     printf("Elapsed time: %d seconds\n",s);
  51.     }
  52.   return 0;
  53.   }
  54.  
  55.  
  56. /* Graphics test -- must have VGA */
  57. int gtest()
  58.   {
  59.   int i,x,y;
  60.   _setvideomode(_MRES256COLOR);
  61.   for (i=1;i<11;i++)
  62.     {
  63.     _setcolor(i);
  64.     for (y=0;y<199;y++)
  65.       for (x=0;x<319;x++)
  66.         _setpixel(x,y);
  67.     }
  68.   _setvideomode(_DEFAULTMODE);
  69.   return 0;
  70.   }
  71.  
  72.  
  73. /* File test -- assumes 320K free on current drive */
  74. char filedata[64000];
  75.  
  76. int ftest()
  77.   {
  78.   FILE *tfile;
  79.   int i,j;
  80.   for (j=0;j<10;j++)
  81.     {
  82.     tfile=fopen("~~TIMING.~@~","w");
  83.     if (!tfile)
  84.       {
  85.       perror("TIMING");
  86.       exit(1);
  87.       }
  88.     for (i=0;i<5;i++)
  89.       fwrite(filedata,sizeof(filedata),1,tfile);
  90.     if (fclose(tfile))
  91.       {
  92.       perror("TIMING");
  93.       }
  94.     unlink("~~TIMING.~@~");
  95.     }
  96.   return 0;
  97.   }
  98.  
  99.  
  100.